package com.yinwq.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.yinwq.springcloud.service.MessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;

/**
 * @author: yinwenqiang@qccr.com
 * @date: Created in 2021/6/20 22:12
 */
//定义消息的推送管道
@EnableBinding(Source.class)
@Slf4j
public class MessageProviderImpl implements MessageProvider {

    // 消息发送管道
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String serial = IdUtil.simpleUUID();
        output.send(MessageBuilder.withPayload(serial).build());
        log.info("*********** send serial: {}", serial);
        return serial;
    }

}
